<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Z轴平移</title>
    <style>
        body {
            width: 100%;
            height: 100%;
            border: 1px solid black;
            background-color: rgb(228, 228, 228);
            perspective: 800px;
        }
        
        .box1 {
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 200px auto;
            /* Z轴平移 调整元素在z轴的位置,即元素和人眼之间的距离 */
            /* 距离越大,离人越近,默认不支持透视,需要手动设置网页的视距 */
            transition: all 1s;
        }
        
        body:hover .box1 {
            transform: translateZ(-200px);
            background-color: cornflowerblue;
        }
    </style>
</head>

<body>
    <div class="box1"></div>
    <!-- <div class="box2"></div> -->
</body>

</html>